class DateRange
  # Given year, month (nullable), day (nullable), return a pair of Date for start and end date
  def self.parse(year, month, day)
    year_start  = year.to_i
    year_end    = year.to_i
    month_start = month.to_i > 0 && month.to_i < 13 ? month.to_i : 1
    month_end   = month.to_i > 0 && month.to_i < 13 ? month.to_i : 12
    day_start   = day.to_i > 0 && day.to_i < 31 ? day.to_i : 1
    day_end     = day.to_i > 0 && day.to_i < 31 ? (day.to_i + 1) : 0
    
    date_start  = Date.new(year_start, month_start, day_start)
    
    if day_end == 0 && month_start != month_end
      # If day and month was not supplied, use 1 year span
      date_end = Date.new(year_start + 1)
    elsif day_end == 0
      # If day was not supplied, use 1 month span
      date_end = date_start >> 1
    else
      date_end = date_start + 1
    end
    
    [date_start, date_end]
  end
end